
using System;
using System.Collections.Generic;
using Assets.Common.DataStruct.Interface;
using UnityEngine;

public class TodoItemSO : ScriptableObject, ITodoItem, IUiNameDescription
{
    [SerializeField]
    string _description;

    [SerializeReference]
    QuestCondition _condition;
    public Dictionary<string, string> QuestArgs;
    public string DisplayName { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
    public string Description { 
        get 
        {
            return _description; 
        }
        set => throw new System.NotImplementedException(); 
    }

    public bool CanComplete()
    {
        return _condition.CheckCondition();
    }
    public void Init()
    {
        if (_condition != null)
        {
            _condition.Init();
            
        }

        if (_condition.ConditonDataArgs != null)
        {
            QuestArgs = _condition.ConditonDataArgs;
        }
        
    }
    /// <summary>
    /// 任务进度变化
    /// </summary>
    /// <param name="action"></param>
    public void RegisterOnUpdate(Action action)
    {
        _condition.OnConditionUpdate += action;
    }
    public string GetProgress()
    {
        return _condition.Progress;
    }
    public void Complete()
    {
        //_condition.OnConditionUpdate. todo 取消监听
        //Debug.Log($"Complete{this}");
    }
}
/// <summary>
/// 注意在SO中改变的数值会被保存,不要不能修改condition 的数据
/// </summary>
public abstract class QuestCondition : ICondition
{
    public abstract bool CheckCondition();
    public virtual void Init() { }
    public Action OnConditionUpdate;
    public abstract string Progress { get; }

    public string CheckFailMessage => throw new NotImplementedException();

    public Dictionary<string, string> ConditonDataArgs;
}

